<?php

include_once "../config.php";
include_once "wxBizMsgCrypt.php";

// 第三方发送消息给公众平台
$WX_THIRD = $GLOBALS['WX_THIRD']['wx377983dffc34bdb8'];

$appId = $WX_THIRD['appid'];
$encodingAesKey = $WX_THIRD['aeskey'];
$token = $WX_THIRD['token'];

$timeStamp = isset($_GET['timestamp']) ? $_GET['timestamp'] : '';
$nonce = isset($_GET['nonce']) ? $_GET['nonce'] : '';
$msg_signature = isset($_GET['msg_signature']) ? $_GET['msg_signature'] : '';

$data = "<xml><ToUserName><![CDATA[oia2Tj我是中文jewbmiOUlr6X-1crbLOvLw]]></ToUserName><FromUserName><![CDATA[gh_7f083739789a]]></FromUserName><CreateTime>1407743423</CreateTime><MsgType><![CDATA[video]]></MsgType><Video><MediaId><![CDATA[eYJ1MbwPRJtOvIEabaxHs7TX2D-HV71s79GUxqdUkjm6Gs2Ed1KF3ulAOA9H1xG0]]></MediaId><Title><![CDATA[testCallBackReplyVideo]]></Title><Description><![CDATA[testCallBackReplyVideo]]></Description></Video></xml>";

$pc = new WXBizMsgCrypt($token, $encodingAesKey, $appId);
$encryptMsg = '';
$errCode = $pc->encryptMsg($data, $timeStamp, $nonce, $encryptMsg);
if ($errCode == 0) {
	print("加密后: " . $encryptMsg . "\n");
} else {
	print($errCode . "\n");
}

$encryptMsg = "<xml><AppId><![CDATA[wxdbdf45b0e026c8ab]]></AppId><Encrypt><![CDATA[PgC/V5mZVChXyk0wFPdO6pYsyLIQj8+O18IonFBNttUyOGGJ1ETbicMc03FEYX3FZo08OqII4Pn5MQOnLjeR8mtdzKrefu1z4ffOsTPj5nxDzAnStpdqznUoc5TP1TWsR6zorfcA6IDRuVflnLGv9W/za+uyvvbC3JWngrI//SsLznSuu2lIpkaLV5obbiekPlLPbtX1DXE3EHcbzW7HCorm3rvpR4sCFYrGwS/Ejcr+7iSTCZHU0tQ6p+ggoQRENdEan/Oi80GGzLq/J98pLRICaSxYPoa6/Xpv/axdBI+SLnkDC/LN0wQQtJqA9Kn98vljG5iGOW5pr8SM39/Phu2DDZjt1DnWx9UujD+RWlBn6zpN7flB+RrKaS+fdR3ytbn4w5CFdMIkCnRvLAejxwT778W1/0Z7CsPk2VWql2nFiH/NGBk8aLBPlHhQyfEXQwHFkpJ0NSxSW9S5/3n7/Q==]]></Encrypt></xml>";

// 第三方收到公众号平台发送的消息
$decryptMsg = '';
$errCode = $pc->decryptMsg($msg_signature, $timeStamp, $nonce, $encryptMsg, $decryptMsg);
if ($errCode == 0) {
	print("解密后: " . $decryptMsg . "\n");
} else {
	print($errCode . "\n");
}
